package com.example.italkapp2.controller.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.italkapp2.R;
import com.example.italkapp2.controller.activity.LoginActivity;
import com.example.italkapp2.controller.activity.SettingActivity;
import com.example.italkapp2.model.Model;
import com.example.italkapp2.utils.myParse;
import com.hyphenate.EMCallBack;
import com.hyphenate.EMClientListener;
import com.hyphenate.chat.EMClient;
import com.example.italkapp2.utils.glide.GlideApp;

public class SettingFragment extends Fragment {
    private TextView tv_setting_name;
    private ImageView headPhoto;
    private Button btn_setting;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view=View.inflate(getActivity(),R.layout.fragment_setting,null);

        intiView(view);

        return view;
    }

    private void intiView(View view){
        tv_setting_name=view.findViewById(R.id.tv_setting_name);
        headPhoto = view.findViewById(R.id.headPhoto);
        String url;
        if (EMClient.getInstance().getCurrentUser().charAt(0) < '0'
                || EMClient.getInstance().getCurrentUser().charAt(0) > '9') {
            url = "https://picsum.photos/id/" +
                    myParse.getInstance().paraseIntInRange(EMClient.getInstance().getCurrentUser(), 1000) + "/200";
        } else {
            url = "https://picsum.photos/id/" + EMClient.getInstance().getCurrentUser() + "/200";
        }
        Log.e("SettingFragment", "https://picsum.photos/id/" + url + "/200");
        GlideApp.with(this).load(url)
                .defaultImg()
                .into(headPhoto);
        btn_setting=view.findViewById(R.id.btn_setting);
        btn_setting.setOnClickListener(v -> startActivity(new Intent(getActivity(), SettingActivity.class)));
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        intiData();
    }

    private void intiData(){
        //头像庞显示当前用户名称
        tv_setting_name.setText(EMClient.getInstance().getCurrentUser());
    }
}